package com.ts.tsjob.services.impl;


import com.alibaba.fastjson.JSONObject;
import com.ts.tsjob.constant.XinShiLiConfigConstant;
import com.ts.tsjob.services.TSKaoQin;
import com.ts.tsjob.util.GetWangBoToken;
import com.ts.tsjob.util.HttpsUtils;
import lombok.extern.log4j.Log4j2;
import org.apache.commons.lang3.StringUtils;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.io.IOException;
import java.text.ParseException;


@Log4j2
@Service("tSKaoQin")
public class TSIKaoQinimpl implements TSKaoQin {

    @Autowired
    private GetWangBoToken getWangBoToken;

    @Override
    public String xuncha(String pageSize, String currentPage) throws IOException, ParseException {
        if (StringUtils.isEmpty(pageSize) && StringUtils.isEmpty(currentPage)) {
            pageSize = "402";
            currentPage = "1";
        }
        log.info("开始调用网格化POST接口");
        //发送请求
        String urlstr = XinShiLiConfigConstant.getXinShiLiTokenPhont();
        JSONObject jsonObject8 = new JSONObject();
        jsonObject8.put("pageSize", pageSize);
        jsonObject8.put("currentPage", currentPage);
        String str = HttpsUtils.sendByHttp(jsonObject8, urlstr, getWangBoToken.getToken());
        System.out.println(str);
        return str;

    }

    @Override
    public String work(String start, String end) throws IOException, ParseException {
        String param = "?start=param1&end=param2";
        param = param.replace("param1", start).replace("param2", end);
        //发送请求
        CloseableHttpClient closeableHttpClient = HttpClients.createDefault();
        String urlstr = XinShiLiConfigConstant.getWall();
        String str = HttpsUtils.sendByHttpGet(null, urlstr + param, getWangBoToken.getToken());
        System.out.println(str);
        return str;

    }

    @Override
    public String chick() throws IOException, ParseException {
        //发送请求
        String urlstr = XinShiLiConfigConstant.getchick();
        String str = HttpsUtils.sendByHttpGet(null, urlstr, getWangBoToken.getToken());
        System.out.println(str);
        return str;
    }

    @Override
    public String yanghu() throws IOException, ParseException {
        //发送请求
        String urlstr = XinShiLiConfigConstant.getMintain();
        String str = HttpsUtils.sendByHttpGet(null, urlstr, getWangBoToken.getToken());
        System.out.println(str);
        return str;
    }

    @Override
    public String shebei() throws IOException, ParseException {
        //发送请求

        String urlstr = XinShiLiConfigConstant.getPatrol();
        String str = HttpsUtils.sendByHttpGet(null, urlstr, getWangBoToken.getToken());
        System.out.println(str);
        return str;

    }

    @Override
    public String guiji(String currentPage, String day, String size) throws IOException, ParseException {
        log.info("======开始执行归点信息接口====");
        JSONObject jsonObject8 = new JSONObject();
        jsonObject8.put("currentPage", currentPage);
        jsonObject8.put("day", day);
        jsonObject8.put("size", size);
        String url = XinShiLiConfigConstant.getPatrolPath();
        String str = HttpsUtils.sendByHttp(jsonObject8, url, getWangBoToken.getToken());
        System.out.println(str);
        return str;
    }

    @Override
    public String danwei() throws IOException, ParseException {
        //发送请求
        CloseableHttpClient closeableHttpClient = HttpClients.createDefault();
        String urlstr = XinShiLiConfigConstant.getdanwei();
        String str = HttpsUtils.sendByHttpGet(null, urlstr, getWangBoToken.getToken());
        System.out.println(str);
        return str;

    }

    @Override
    public String penpen(String id) throws IOException, ParseException {
        //发送请求
        String urlstr = XinShiLiConfigConstant.getPenpone(id);
        String str = HttpsUtils.sendByHttpGet(null, urlstr, getWangBoToken.getToken());
        System.out.println(str);
        return str;

    }
}

